package cn.com.backstage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.api.entity.ApiU_advert_position;

import cn.com.api.service.ApiU_advert_positionService;
import cn.com.backstage.controller.base.U_advert_positionBaseController;

import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_BACKSTAGE + "/")
public class U_advert_positionController extends U_advert_positionBaseController {

	private static Logger logger = Logger.getLogger(U_advert_positionController.class);

	@Autowired
	private ApiU_advert_positionService apiU_advert_positionService;

	/**
	 * 新增或者编辑
	 * 
	 * @return
	 */
	@RequestMapping(value = "advert_position-add")
	public void advert_position_add(HttpServletRequest request, HttpServletResponse response,
			ApiU_advert_position u_advert_position) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		Integer id = u_advert_position.getId();

		if (id == null || id == 0) { // add
			apiU_advert_positionService.insertU_advert_position(u_advert_position);
		} else {// edit
			ApiU_advert_position oldposition = apiU_advert_positionService
					.findU_advert_positionById(Integer.valueOf(id));
			oldposition.setPosition_name(u_advert_position.getPosition_name());
			oldposition.setPre_picture(u_advert_position.getPre_picture());
			oldposition.setUnit_price(u_advert_position.getUnit_price());
			oldposition.setUnit(u_advert_position.getUnit());
			oldposition.setSpec(u_advert_position.getSpec());
			oldposition.setPre_prcture_inn(u_advert_position.getPre_prcture_inn());
			oldposition.setSpec_inn(u_advert_position.getSpec_inn());
			apiU_advert_positionService.updateU_advert_position(oldposition);
		}
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "操作成功！");
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

}
